<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>产品生产工序设计单审核</title>
</head>
<!-- 新 Bootstrap4 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">


<link rel="stylesheet" href="../../css/bootstrap-table.min.css">

<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>

<!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单，包含了 popper.min.js -->
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>

<!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>



<script src="../../js/bootstrap-table.min.js"></script>

<script src="../../js/bootstrap-table-zh-CN.min.js"></script>
<body>
<!--审核：制定设计单-->
<div class="modal fade" id="zhidingshejidan">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
                <h6 class="modal-title">您正在做的业务是：生产管理--产品生产工序设计--制定产品生产工序设计单</h6>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- 模态框主体 -->
            <div class="modal-body" style="background-color: darkgray;">
                <div style="display: flex;justify-content: flex-end">
                   <label style="margin-right: 10px;margin-top: 10px;"><input type="radio" name="xz" class="radio" value="通过"> 通过</label>
                    <label style="margin-right: 15px;margin-top: 10px;"> <input type="radio" name="xz" class="radio" checked value="不通过"> 不通过</label>
                    <button type="button" class="btn btn-info" onclick="checkokorno()" data-dismiss="modal">确定</button>
                    <button type="button" class="btn btn-secondary"style="margin-left: 5px;" data-dismiss="modal">返回</button>
                </div>

                <div style="border: 1px solid black;margin-top: 10px; background-color: white;display: flex;flex-direction: column">
                    <h5 style="text-align: center;margin-top: 20px">生产工序设计单</h5>
                    <div style="display: flex;">
                        <div  style="margin-left: 10%;width: 40%;" >设计单编号：<span id="sheng_designId"></span></div>
                        <div style="width: 40%;display: flex"><div style="width: 23%">设计人：</div><input id="sheng_designer"  style="outline: none;border: none;border-bottom: 1px solid black;width: 80%"></div>
                    </div>
                    <div  style="display: flex;margin-top: 5px;">
                        <div  style="margin-left: 10%;width: 30%;" >产品名称：<span id="sheng_productName"></span></div>
                        <div  style="margin-left: 10%;width: 40%;" >产品编号：<span id="sheng_productId"></span></div>
                    </div>
                    <div style="display: flex;">
                        <table class="table-sm  table-hover table-bordered" id="shengcahngtab" style="margin-left: 10%;margin-top: 5px;text-align: center"  cellpadding="0" cellspacing="0" width="80%;">
                            <tr class="table-primary" style="color: white">
                                <td>工序序号</td>
                                <td>工序名称</td>
                                <td>工序编号</td>
                                <td>描述</td>
                                <td>工时数</td>
                                <td>工时单位</td>
                                <td>工时成本</td>
                                <td>工时成本小计（元）</td>
                            </tr>
                        </table>
                    </div>
                    <div>
                    <div  style="margin-left: 10%;width: 30%;margin-top: 5px;" >工时总成本：<span id="sheng_costPriceSum"></span></div>
                    </div>
                    <div  style="display: flex;">
                        <div style="margin-left: 10%;margin-top: 5px;">
                            审核人 ：</div><input id="sheng_checker"  style="outline: none;border: none;border-bottom: 1px solid black;width: 30%;">
                        <div style="margin-left: 45px;margin-top: 20px;">审核时间：<span id="sheng_checkTime"></span></div>
                    </div>
                    <div style="display: flex;">
                        <div style="margin-left:10%;margin-top: 5px;display: flex;width: 100%;margin-bottom: 30px;">
                            设计要求：
                            <textarea id="sheng_procedureDescribe" rows="3" style="width: 77%;margin-top: 20px;"></textarea>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
<div>
    <table id="check_tabb">

    </table>
</div>

<script>
    //页面加载事件
    $(function () {
        $("#check_tabb").bootstrapTable({
            method: "post",
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            url: "/lc/querycheckproductionprocesses",
            striped: true,
            pageNumber: 1,
            pagination: true,
            sidePagination: "server",
            pageSize: 3,
            pageList: [3, 5, 8, 10],
            queryParams: function (parms) {
                return {
                    pageNumber: (parms.offset / parms.limit) + 1,
                    pageSize: parms.limit,
                }
            },
            columns: [
                {title: "设计单编号", field: "designId", align: "center"},
                {title: "产品编号", field: "productId", align: "center"},
                {title: "产品名称", field: "productName", align: "center"},
                {title: "设计人", field: "designer", align: "center"},
                {title: "登记时间", field: "registerTime", align: "center"},
                {title: "工时总成本", field: "costPriceSum", align: "center"},
                {title: "审核", field: "designId", align: "center",
         formatter: function (value, row, index) {
             //方式1
             /*var btn1="<button  class='btn btn-primary btn-sm' data-toggle='modal' onclick='editEmp("+JSON.stringify(row)+")' data-target='#myModal'>修改</button>";*/
             //方式2
             var btn1 = "<button  class=\"btn btn-primary btn-sm\" data-toggle=\"modal\" onclick='zhidingshejicheck("+JSON.stringify(row)+")' data-target=\"#zhidingshejidan\">审核</button>";
             return btn1;
         }},
            ],
        })

    })
    function  zhidingshejicheck(checkdata) {
        $(".sheng_tr").remove();
        $("#sheng_designId").text(checkdata.designId)
        $("#sheng_productName").text(checkdata.productName)
        $("#sheng_productId").text(checkdata.productId)
        $("#sheng_costPriceSum").text(checkdata.costPriceSum)
        $("#sheng_checker").val(checkdata.register)
        $("#sheng_designer").val(checkdata.designer);
        $("#sheng_procedureDescribe").val(checkdata.procedureDescribe);

        var myDate = new Date;
        $("#sheng_checkTime").text(myDate.toLocaleString())

        $.ajax({
            type:"POST",
            data:"id="+checkdata.id,
            url:"/lc/queryByidcheckmingxi",
            success:function (iddata) {
                $.each(iddata,function (index,d) {
                    $("#shengcahngtab").append("<tr class='sheng_tr'>" +
                        "<td>"+d.detailsNumber+"</td>" +
                        "<td>"+d.procedureName+"</td>" +
                        "<td>"+d.procedureId+"</td>" +
                        "<td><input type='hidden' value='"+d.id+"'></td>" +
                        "<td><input type='number' readonly='readonly'   value='"+d.labourHourAmount+"' style='border: none;outline: none;width: 40px;'></td>" +
                        "<td><input type='text' readonly='readonly' value='"+d.amountUnit+"' style='border: none;outline: none;width: 40px;'></td>" +
                        "<td><input type='number' readonly='readonly' value='"+d.costPrice+"' style='border: none;outline: none;width: 40px;'></td>" +
                        "<td>"+d.subtotal+"</td>" +
                        "</tr>")
                })
            }
        })
    }
    
    function  checkokorno() {
        //设计单obj

        var gxmxobj={};
        var gxmxsum=[];
        var sumzcb=0;
        $(".sheng_tr").each(function () {
            sumzcb+=parseInt($(this).find(" td:eq(4)>input").val()*$(this).find(" td:eq(6)>input").val());
            gxmxobj={
                id:$(this).find(" td:eq(3)>input").val(),
                detailsNumber:$(this).find(" td:eq(0)").text(),
                procedureId:$(this).find(" td:eq(2)").text(),
                procedureName:$(this).find(" td:eq(1)").text(),
                labourHourAmount:parseInt($(this).find(" td:eq(4)>input").val()),
                amountUnit:$(this).find(" td:eq(5)>input").val(),
                costPrice:parseInt($(this).find(" td:eq(6)>input").val()),
                subtotal:parseInt($(this).find(" td:eq(4)>input").val()*$(this).find(" td:eq(6)>input").val())
            }
            gxmxsum.push(gxmxobj)
        })
        var shejiobj={
            designId:$("#sheng_designId").text(),
            productId:$("#sheng_productId").text(),
            productName:$("#sheng_productName").text(),
            procedureDescribe:$("#sheng_procedureDescribe").val(),
            costPriceSum:parseInt(sumzcb),
            designer:$("#sheng_designer").val(),
            checker:$("#sheng_checker").val(),
            checkTime:$("#sheng_checkTime").text()
        }
        if($("input[name='xz']:checked").val()=='通过'){
           $.ajax({
               type:"POST",
               url:"/lc/shenghecheckok",
               contentType: 'application/json',
               data: JSON.stringify({mdesignProcedure:shejiobj,
                   mdesignProcedureDetailslist:gxmxsum}),
               success:function (cc) {
                   $("#check_tabb").bootstrapTable("refresh");
               }
           })
        }else{
            // 不通过
           $.ajax({
               type:"POST",
               url:"/lc/shenghecheckno",
               contentType: 'application/json',
               data: JSON.stringify({mdesignProcedure:shejiobj,
                   mdesignProcedureDetailslist:gxmxsum}),
               success:function (zz) {
                   $("#check_tabb").bootstrapTable("refresh");
               }
           })
        }
    }


</script>
</body>
</html>